package com.ruoyi.web.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import com.ruoyi.common.config.pay.CommonFieldName;
import com.ruoyi.common.config.pay.OrderIdGenerator;
import com.ruoyi.web.request.IESI123104Request;
import com.ruoyi.web.request.IESI123108Request;
import com.ruoyi.web.service.AgentPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.mapper.PaymentLimitRefundMapper;
import com.ruoyi.web.domain.PaymentLimitRefund;
import com.ruoyi.web.service.IPaymentLimitRefundService;
import com.ruoyi.common.core.text.Convert;

/**
 * 代付限额退款Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-04-04
 */
@Service
public class PaymentLimitRefundServiceImpl implements IPaymentLimitRefundService 
{
    @Autowired
    private PaymentLimitRefundMapper paymentLimitRefundMapper;
    @Autowired
    private AgentPayService agentPayService;
    /**
     * 查询代付限额退款
     * 
     * @param sequenceNo 代付限额退款ID
     * @return 代付限额退款
     */
    @Override
    public PaymentLimitRefund selectPaymentLimitRefundById(String sequenceNo)
    {
        return paymentLimitRefundMapper.selectPaymentLimitRefundById(sequenceNo);
    }

    /**
     * 查询代付限额退款列表
     * 
     * @param paymentLimitRefund 代付限额退款
     * @return 代付限额退款
     */
    @Override
    public List<PaymentLimitRefund> selectPaymentLimitRefundList(PaymentLimitRefund paymentLimitRefund)
    {
        return paymentLimitRefundMapper.selectPaymentLimitRefundList(paymentLimitRefund);
    }

    /**
     * 新增代付限额退款
     * 
     * @param paymentLimitRefund 代付限额退款
     * @return 结果
     */
    @Override
    public int insertPaymentLimitRefund(PaymentLimitRefund paymentLimitRefund) throws Exception
    {

        IESI123108Request request =new IESI123108Request();
        request.setType("T1");
        request.setAddInfo(paymentLimitRefund.getAddInfo());
        paymentLimitRefund.setSequenceNo(OrderIdGenerator.getDefault().nextId());
        HashMap<String, Object> resultMap= agentPayService.IESI123108(request,paymentLimitRefund.getSequenceNo(),paymentLimitRefund.getMerchCd());
        String respCode = (String) resultMap.get(CommonFieldName.RESP_CODE);
        String respMsg = (String) resultMap.get(CommonFieldName.RESP_MSG);
        paymentLimitRefund.setStatus(respCode);
        paymentLimitRefund.setMsg(respMsg);
        return paymentLimitRefundMapper.insertPaymentLimitRefund(paymentLimitRefund);
    }

    /**
     * 修改代付限额退款
     * 
     * @param paymentLimitRefund 代付限额退款
     * @return 结果
     */
    @Override
    public int updatePaymentLimitRefund(PaymentLimitRefund paymentLimitRefund)
    {
        return paymentLimitRefundMapper.updatePaymentLimitRefund(paymentLimitRefund);
    }

    /**
     * 删除代付限额退款对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePaymentLimitRefundByIds(String ids)
    {
        return paymentLimitRefundMapper.deletePaymentLimitRefundByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除代付限额退款信息
     * 
     * @param sequenceNo 代付限额退款ID
     * @return 结果
     */
    @Override
    public int deletePaymentLimitRefundById(String sequenceNo)
    {
        return paymentLimitRefundMapper.deletePaymentLimitRefundById(sequenceNo);
    }
}
